package com.shangyitong.yygh_user.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shangyitong.Result;
import com.shangyitong.yygh.model.user.UserInfo;
import com.shangyitong.yygh.vo.user.UserInfoQueryVo;
import com.shangyitong.yygh_user.service.UserService;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/admin/user")
@Slf4j
public class UserController {
    @Autowired
    private UserService userService;
    /**
     * 管理端用户列表
     * finished
     * @param page
     * @param limit
     * @return
     */
    @ApiOperation(value = "用户列表")
    @GetMapping("/{page}/{limit}")
    public Result getPageList(@PathVariable Integer page,
                              @PathVariable Integer limit,
                              UserInfoQueryVo userInfoQueryVo) {
        Page<UserInfo> pageList = userService.getPageList(page, limit, userInfoQueryVo);
        return Result.ok(pageList);
    }

    /**
     * 后台查看用户信息
     * finished
     * @param id
     * @return
     */
    @ApiOperation(value = "后台查看用户信息")
    @GetMapping("show/{id}")
    public Result showUserDetail(@PathVariable Long id){
        Map<String, Object> userMap = userService.showUserDetail(id);
        return Result.ok(userMap);
    }

    /**
     * 进行用户锁定
     * finished
     * @param id
     * @param status
     * @return
     */
    @ApiOperation(value = "用户锁定")
    @GetMapping("lock/{id}/{status}")
    public Result lockUser(@PathVariable Long id,
                           @PathVariable Integer status){
        UserInfo userInfo = userService.getById(id);
        userInfo.setStatus(status);
        boolean update = userService.updateById(userInfo);
        if (update){
            return Result.ok();
        }
        return Result.fail();
    }

    /**
     * 认证审批
     * @param id
     * @param authStatus
     * @return
     */
    @ApiOperation(value = "认证审批")
    @GetMapping("approval/{id}/{authStatus}")
    public Result approvalUser(@PathVariable Long id,
                               @PathVariable Integer authStatus){
        UserInfo userInfo = userService.getById(id);
        userInfo.setAuthStatus(authStatus);
        boolean update = userService.updateById(userInfo);
        if (update){
            return Result.ok();
        }
        return Result.fail();
    }
}
